import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;

public class RunFibo {
    public static void main(String[] args) {
        long start = new Date().getTime();
        boolean flag =false;
        if(flag) {
            //未加入线程池 832040,用时3164
            Fibonac fb = new Fibonac(30);
            long result = fb.compute();
            long span = new Date().getTime() - start;
            System.out.println(result + ",用时"+span);
        }else {
            //加入线程池计算  结果832040,用时6235
            ForkJoinPool pool = (ForkJoinPool) Executors.newWorkStealingPool();
            FibonacFork task = new FibonacFork(30);
            Future<Integer> future = pool.submit(task);
            try {
                int result = future.get();
                long span = new Date().getTime() - start;
                System.out.println(result + ",用时"+span);
                pool.shutdown();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


    }
}
